﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestSubtractCMFlattenDenseMatrix.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Sequential.Tests.CMFlattenDenseMatrixTest.DoubleExtensions
{
    #region Usings

    using System;

    using ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions;

    using NUnit.Framework;

    #endregion

    /// <summary>
    ///     Test suite for
    ///     <see cref="CMFlattenDenseMatrixExtensions.Subtract(CMFlattenDenseMatrix{double},CMFlattenDenseMatrix{double})"/>.
    /// </summary>
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions.CMFlattenDenseMatrixExtensions")]
    public sealed class TestSubtractCMFlattenDenseMatrix
    {
        /// <summary>
        ///     Tests the method when minuend and subtrahend have the same size.
        /// </summary>
        [Test]
        public void WhenMinuendAndSubtrahendHaveTheSameSize()
        {
            // Arrange
            var minuendData = new double[]
                              {
                                  10, 15,
                                  20, 25,
                                  30, 35
                              };
            var minuend = new CMFlattenDenseMatrix<double>(2, 3, minuendData);
            var subtrahendData = new double[]
                                 {
                                     1, 2,
                                     3, 4,
                                     5, 6
                                 };
            var subtrahend = new CMFlattenDenseMatrix<double>(2, 3, subtrahendData);
            var expected = new[]
                           {
                               9, 13,
                               17, 21,
                               25, 29
                           };

            // Act
            minuend.Subtract(subtrahend);

            // Assert
            Assert.That(minuend.Values, Is.EquivalentTo(expected));
        }

        /// <summary>
        ///     Tests the method when subtrahend has less count of rows than minuend.
        /// </summary>
        [Test]
        public void WhenSubtrahendHasLessRowsCountThanMinuend()
        {
            // Arrange
            var minuendData = new double[]
                              {
                                  10, 15,
                                  20, 25,
                                  30, 35
                              };
            var minuend = new CMFlattenDenseMatrix<double>(2, 3, minuendData);
            var subtrahendData = new double[]
                                 {
                                     1,
                                     2,
                                     3
                                 };
            var subtrahend = new CMFlattenDenseMatrix<double>(1, 3, subtrahendData);
            var expected = new[]
                           {
                               9, 15,
                               18, 25,
                               27, 35
                           };

            // Act
            minuend.Subtract(subtrahend);

            // Assert
            Assert.That(minuend.Values, Is.EquivalentTo(expected));
        }

        /// <summary>
        ///     Tests the method when subtrahend have greater count of rows than minuend.
        /// </summary>
        [Test]
        public void WhenSubtrahendHasGreaterRowsCountThanMinuend()
        {
            // Arrange
            var minuendData = new double[]
                              {
                                  10, 15,
                                  20, 25,
                                  30, 35
                              };
            var minuend = new CMFlattenDenseMatrix<double>(2, 3, minuendData);
            var subtrahendData = new double[]
                                 {
                                     1, 2, 3,
                                     4, 5, 6,
                                     7, 8, 9
                                 };
            var subtrahend = new CMFlattenDenseMatrix<double>(3, 3, subtrahendData);
            var expected = new[]
                           {
                               9, 13,
                               16, 20,
                               23, 27
                           };

            // Act
            minuend.Subtract(subtrahend);

            // Assert
            Assert.That(minuend.Values, Is.EquivalentTo(expected));
        }

        /// <summary>
        ///     Tests the method when subtrahend has less count of columns than minuend.
        /// </summary>
        [Test]
        public void WhenSubtrahendHasLessColumnsCountThanMinuend()
        {
            // Arrange
            var minuendData = new double[]
                              {
                                  10, 15,
                                  20, 25,
                                  30, 35
                              };
            var minuend = new CMFlattenDenseMatrix<double>(2, 3, minuendData);
            var subtrahendData = new double[]
                                 {
                                     1, 2,
                                     3, 4
                                 };
            var subtrahend = new CMFlattenDenseMatrix<double>(2, 2, subtrahendData);
            var expected = new[]
                           {
                               9, 13,
                               17, 21,
                               30, 35
                           };

            // Act
            minuend.Subtract(subtrahend);

            // Assert
            Assert.That(minuend.Values, Is.EquivalentTo(expected));
        }

        /// <summary>
        ///     Tests the method when subtrahend has greater count of columns than minuend.
        /// </summary>
        [Test]
        public void WhenSubtrahendHasGreaterColumnsCountThanMinuend()
        {
            // Arrange
            var minuendData = new double[]
                              {
                                  10, 15,
                                  20, 25,
                                  30, 35
                              };
            var minuend = new CMFlattenDenseMatrix<double>(2, 3, minuendData);
            var subtrahendData = new double[]
                                 {
                                     1, 2,
                                     3, 4,
                                     5, 6,
                                     7, 8
                                 };
            var subtrahend = new CMFlattenDenseMatrix<double>(2, 4, subtrahendData);
            var expected = new[]
                           {
                               9, 13,
                               17, 21,
                               25, 29
                           };

            // Act
            minuend.Subtract(subtrahend);

            // Assert
            Assert.That(minuend.Values, Is.EquivalentTo(expected));
        }

#if SAFE

        /// <summary>
        ///     Tests the method when minuend is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenMinuendIsNull()
        {
            // Arrange
            var subtrahend = new CMFlattenDenseMatrix<double>(2, 3);

            // Act and Assert
            Assert.That(
                () => CMFlattenDenseMatrixExtensions.Subtract(null, subtrahend),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("minuend"));
        }

        /// <summary>
        ///     Tests the method when subtrahend is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenSubtrahendIsNull()
        {
            // Arrange
            var minuend = new CMFlattenDenseMatrix<double>(2, 3);

            // Act and Assert
            Assert.That(
                () => minuend.Subtract(null),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("subtrahend"));
        }

#endif
    }
}